<template name='user_astrict'>

<view style="display: flex;    height: 100%;">
	<!-- 商品信息-右边 -->
	<view class="box-infos font12 " >

		<!-- 数据列表 -->
		<view class="content-box " >
			<view class="boxsss40" >
				<!-- 增加、删除 -->
				<view class="top-but">
					<view class="top-but-box">
						
						<!-- 操作区-->
						<view class="flex floatleft" >
							<view selectable="true"  class="riskTitle left10">搜索用户关键字:</view>
							<!-- 搜索 -->
							<view class="searchBox">
								<input 
								v-model="sousou.value"
								placeholder="输入客户的关键字"
								placeholder-class="placeholder-class"
								@confirm="loadData(true)"
								class="search-ipu w200"
								:focus="focus.word"
								@blur="focus.word=false"
								/>
								<view class="delete-ipu" v-if="sousou.value!=''" @click="sousou.value='',focus.word=true">
									<img src="../../static/img/delete-1.png"  ></img>
								</view>
							</view>
						</view>
						<!-- end -->
						<view @click="$common.noMultipleClicks('loadData',loadData,true)" class="rightButttom" >
							<img src="../../static/img/search.png" class="ico"></img>
							刷新
						</view>
					</view>
				</view>
				
				<table id="user_astrict" v-if="resData.list!=undefined && resData.list.length>0">
					<!-- 表头 -->
					<thead>
						<tr >
							<th class="centers ">
								账号
							</th>
							<th class="centers " @click="$common.changeColumnColor('user_astrict',0)">
								财务过账
							</th>
							<th class="centers " @click="$common.changeColumnColor('user_astrict',1)">
								单据回款
							</th>
							<th class="centers " @click="$common.changeColumnColor('user_astrict',2)">
								代客户下单
							</th>
							<th class="centers " @click="$common.changeColumnColor('user_astrict',3)">
								下单时修改价格
							</th>
							<th class="centers "  title="查看历史的开单价格"@click="$common.changeColumnColor('user_astrict',4)">
								查看历史价格
							</th>
							<th class="centers "  title="开启后在业务员下单的时候，下单框会自动置入上一次下单的价格;避免同一个客户同一个商品的价格混乱"@click="$common.changeColumnColor('user_astrict',5)">
								下单时价格跟踪
							</th>
							<th class="centers " @click="$common.changeColumnColor('user_astrict',6)">
								添加商品
							</th>
							<th class="centers " @click="$common.changeColumnColor('user_astrict',7)">
								上传商品图片
							</th>
							<th class="centers " @click="$common.changeColumnColor('user_astrict',8)">
								修改商品货位
							</th>
							<th class="centers " @click="$common.changeColumnColor('user_astrict',9)">
								修改商品库存
							</th>
							<th class="centers " @click="$common.changeColumnColor('user_astrict',10)">
								查看单据、商品利润
							</th>
							<th class="centers " @click="$common.changeColumnColor('user_astrict',11)">
								添加线路
							</th>
							<th class="centers " @click="$common.changeColumnColor('user_astrict',12)">
								添加客户
							</th>
							<th class="centers " @click="$common.changeColumnColor('user_astrict',13)">
								修改客户
							</th>
							<th class="centers " @click="$common.changeColumnColor('user_astrict',14)">
								封禁账号
							</th>
							<th class="centers " @click="$common.changeColumnColor('user_astrict',15)">
								商城设置
							</th>
							<th class="centers " @click="$common.changeColumnColor('user_astrict',16)">
								单据打印
							</th>
							<th class="centers " @click="$common.changeColumnColor('user_astrict',17)">
								撤回已过账的订单
							</th>
							<th class="centers " @click="$common.changeColumnColor('user_astrict',18)">
								修改打印后的订单
							</th>
						</tr>
					</thead>
					<tbody>
						<!-- 内容 -->
						<tr v-for="(user,index) in resData.list" 
						:key="index"
						@click="TabcheckedIndex = index"
						:class="TabcheckedIndex == index ? 'goods-list-select':''"
						:style="user.prevent==2 ? 'color:#f00':''"
						>
							<td class="centers ">
								{{user.name}}
							</td>
							
							<td class="col-0">
								<switch  
								@change="(val)=>{change(val,'up_goods_guozhang',index)}" 
								:checked="user.astrict.up_goods_guozhang==0" class="centers"
								style="transform:scale(0.5);"
								/>
							</td>
							<td class="col-1">
								<switch  @change="(val)=>{change(val,'up_order_money',index)}" 
								:checked="user.astrict.up_order_money==0" class="centers"
								style="transform:scale(0.5);"
								/>
							</td>
							<td class="col-2">
								<switch  
								@change="(val)=>{change(val,'up_order_add',index)}" 
								:checked="user.astrict.up_order_add==0" class="centers"
								style="transform:scale(0.5);"
								/>
							</td>
							<td class="col-3">
								<switch  
								@change="(val)=>{change(val,'up_goods_pifajia',index)}" 
								:checked="user.astrict.up_goods_pifajia==0" class="centers"
								style="transform:scale(0.5);"
								/>
							</td>
							<td class="col-4">
								<switch  @change="(val)=>{change(val,'up_goods_records',index)}" 
								:checked="user.astrict.up_goods_records==0" class="centers"
								style="transform:scale(0.5);"
								/>
							</td>
							<td class="col-5">
								<switch  @change="(val)=>{change(val,'up_goods_recordsMoney',index)}"
								:checked="user.astrict.up_goods_recordsMoney==0" class="centers"
								style="transform:scale(0.5);"
								/>
							</td>
							<td class="col-6">
								<switch  @change="(val)=>{change(val,'up_goods_update',index)}" 
								:checked="user.astrict.up_goods_update==0" class="centers"
								style="transform:scale(0.5);"
								/>
							</td>
							<td class="col-7">
								<switch  @change="(val)=>{change(val,'up_goods_upload_img',index)}" 
								:checked="user.astrict.up_goods_upload_img==0" class="centers"
								style="transform:scale(0.5);"
								/>
							</td>
							<td class="col-8">
								<switch  @change="(val)=>{change(val,'up_goods_check',index)}" 
								:checked="user.astrict.up_goods_check==0" class="centers"
								style="transform:scale(0.5);"
								/>
							</td>
							<td class="col-9">
								<switch  @change="(val)=>{change(val,'update_check',index)}"
								:checked="user.astrict.update_check==0" class="centers"
								style="transform:scale(0.5);"
								/>
							</td>
							<td class="col-10">
								<switch  @change="(val)=>{change(val,'up_money_profit',index)}"
								:checked="user.astrict.up_money_profit==0" class="centers"
								style="transform:scale(0.5);"
								/>
							</td>
							<td class="col-11">
								<switch  @change="(val)=>{change(val,'up_route_add',index)}" 
								:checked="user.astrict.up_route_add==0" class="centers"
								style="transform:scale(0.5);"
								/>
							</td>
							<td class="col-12">
								<switch  @change="(val)=>{change(val,'up_user_add',index)}" 
								:checked="user.astrict.up_user_add==0" class="centers"
								style="transform:scale(0.5);"
								/>
							</td>
							<td class="col-13">
								<switch  @change="(val)=>{change(val,'up_user_update',index)}" 
								:checked="user.astrict.up_user_update==0"  class="centers"
								style="transform:scale(0.5);"
								/>
							</td>
							<td class="col-14">
								<switch  @change="(val)=>{change(val,'up_user_prevent',index)}" 
								:checked="user.astrict.up_user_prevent==0"  class="centers"
								style="transform:scale(0.5);"
								/>
							</td>
							<td class="col-15">
								<switch  @change="(val)=>{change(val,'up_mp_setting',index)}"
								:checked="user.astrict.up_mp_setting==0"  class="centers"
								style="transform:scale(0.5);"
								/>
							</td>
							<td class="col-16">
								<switch  @change="(val)=>{change(val,'up_print',index)}"
								:checked="user.astrict.up_print==0"  class="centers"
								style="transform:scale(0.5);"
								/>
							</td>
							<td class="col-17">
								<switch  @change="(val)=>{change(val,'up_order_back',index)}"
								:checked="user.astrict.up_order_back==0"  class="centers"
								style="transform:scale(0.5);"
								/>
							</td>
							<td class="col-18">
								<switch  @change="(val)=>{change(val,'up_print_update',index)}"
								:checked="user.astrict.up_print_update==0"  class="centers"
								style="transform:scale(0.5);"
								/>
							</td>
						</tr>
					</tbody>
				</table>
				
				<!-- 暂无数据 -->
				<empty v-if="resData.list==undefined || resData.list.length==0"></empty>
				<!-- end -->
			</view>
			
			
			
			
		
			<!-- 页码 -->
			<pages 
			:sum="page.sum"
			:current="page.nowPage"
			@updatePage="updatePage"
			></pages>
			<!-- end -->
		</view>
		<!-- 数据列表end -->

	</view>
</view>


</template>

<script>
	import pages from "@/components/admin-components/pages.vue"
	import empty from "@/components/admin-components/empty.vue"
	export default{
		name:'user_astrict',
		components: {
			pages,empty
		},
		data(){
			return{
				focus:{
					word:false
				},
				TabcheckedIndex:-1,//当前选中项
				qx_width:0,//权限表格的宽度
				page:{
					
					nowPage:1,//当前页数
					pageCount:1,//总页数
					maxCount:0,
					sum:0,
					pageCounts:15,
				},
				sousou:{
					value:''
				},
				resData:{},
				resData_astrict:{},
			
			}
		},
		 // 此处定义传入的数据
		props: {
			OnPageSearch:''
		},
		mounted(){
		},
		created() {
			if(this.OnPageSearch != undefined && this.OnPageSearch != ''){
				this.sousou.value = this.OnPageSearch
				
			}
			this.loadData()
			
			
			
		},
		methods:{
			change(item,name,index){
				this.resData.list[index].astrict[name] = item.detail.value==false? 1:0;
				this.fun_save_astrict(index)
			},
	 
		 /**
		  * 分页器回调
		  * 
		 */
		 updatePage(pageName,pageCount){
			var that = this
		 
			that.page.nowPage = pageName
			that.page.pageCounts = pageCount
			that.loadData(false)
		 },

			/**
			 * 读取用户
			 * type : goods_list|goods_search
			 * 
			*/
			loadData(isUpdatePage=true){
				var that = this
				that.TabcheckedIndex=0//初始化列表选中项
				that.page.nowPage = isUpdatePage == true ? 1:that.page.nowPage;
				that.$common.get_request(
					{
						type:'firm_user_list',
						user_type:'yg',
						astrict:'astrict',//返回权限接口
						search:that.sousou.value,//搜索内容
						is_map:1
					},
					
					(res)=>{
						
						that.page.sum  = res.sum
						if(isUpdatePage == true){
						that.page.nowPage  = 1
						}
						
						//获取权限数量，然后平均分表格宽度
						if(res.list.length>0){
							var count = Object.keys(res.list[0].astrict).length -1
							this.qx_width = (90 / count) +'%';
							
						}
						that.resData = res
					}
				);
			},
			
			/**
			 * 保存权力列表
			 * type : goods_list|goods_search
			 * 
			*/
			fun_save_astrict(index){
			
				var that = this
				var jsonData = JSON.stringify(that.resData.list[index].astrict)
				that.$common.get_request(
					{
						type:'user_astrict',
						json_data:jsonData,
						uid:that.resData.list[index].id,
					},
					(res)=>{
						that.$common.toast(res.msg)
					}
				);
			},
			
		}
	}
</script>

<style>
</style>
